home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 2
/
Deutsche Edition 2.iso
/
mac
/
POWERMAC
/
C64
/
SOURCE
/
AppleEvents.c
< prev
next >
Wrap
Text File
|
1994-06-06
|
7KB
|
265 lines
/*
Commodore 64 Emulator v0.4 Earle F. Philhower III
Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <AppleEvents.h>
#include "Processor.h"
#include "Error.h"
#include "FileTypes.h"
int AppleEventInitialize(void);
OSErr DoQUIT(void), DoOAPP(void);
OSErr DoODOC(const AppleEvent *theAE,const AppleEvent *theRp);
OSErr DoPDOC(const AppleEvent *theAE,const AppleEvent *theRp);
extern void CleanUpCommodore(void);
void OpenFSSpec(FSSpec *spec);
void PrintFSSpec(FSSpec *spec);
void AttachFloppyImage(FSSpec *spec);
void LoadRAMFS(FSSpec *spec);
void LoadTapeFS(FSSpec *spec);
#ifndef __MWERKS__
pascal OSErr AEHandleQUIT(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
pascal OSErr AEHandleOAPP(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
pascal OSErr AEHandleODOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
pascal OSErr AEHandlePDOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
#else
static AEEventHandlerUPP myQUITAEHandler = NULL;
static AEEventHandlerUPP myOAPPAEHandler = NULL;
static AEEventHandlerUPP myODOCAEHandler = NULL;
static AEEventHandlerUPP myPDOCAEHandler = NULL;
pascal OSErr AEHandleQUIT(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
pascal OSErr AEHandleOAPP(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
pascal OSErr AEHandleODOC(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
pascal OSErr AEHandlePDOC(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
#endif
static DescType missedTypeCode;
static long missedActualSize;
#define InstallFinder(z,y) AEInstallEventHandler(kCoreEventClass, z, y, 0, false)
#define MissedParams(z) \
(AESizeOfAttribute(z, keyMissedKeywordAttr, \
&missedTypeCode, &missedActualSize) != errAEDescNotFound)
OSErr DoQUIT(void)
{
CleanUpCommodore();
ExitToShell();
}
pascal OSErr AEHandleQUIT(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
err = DoQUIT();
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
/* There should be NO parameters sent to us..if there are, someone's
got a REAL problem! (not us, though!) */
return(err);
}
OSErr DoOAPP()
{
return noErr;
}
pascal OSErr AEHandleOAPP(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
err = DoOAPP();
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
return(err);
}
void OpenFSSpec(FSSpec *spec)
{
FInfo fInfo;
FSpGetFInfo(spec, &fInfo);
switch(fInfo.fdType)
{
case DISKFTYPE:
AttachFloppyImage(spec);
break;
case RAMFTYPE:
LoadRAMFS(spec);
break;
case PRINTERFTYPE:
break;
case TAPEFTYPE:
LoadTapeFS(spec);
break;
}
}
void PrintFSSpec(FSSpec *spec)
{
FInfo fInfo;
FSpGetFInfo(spec, &fInfo);
switch(fInfo.fdType)
{
case DISKFTYPE:
break;
case RAMFTYPE:
break;
case PRINTERFTYPE:
break;
case TAPEFTYPE:
break;
}
}
OSErr DoODOC(theAppleEvent, theReply)
const AppleEvent *theAppleEvent, *theReply;
{
OSErr err;
FSSpec myFSS;
AEDescList *docList;
long items;
long index;
AEKeyword keywd;
DescType typeCode;
Size actualSize;
err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
if (err!=noErr) return (err);
err = AECountItems(docList, &items);
if (err!=noErr) return (err);
for (index=1; index<=items; index++)
{
err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode,(Ptr)&myFSS,
sizeof(myFSS), &actualSize );
if (err!=noErr)
{
AEDisposeDesc(docList);
return (err);
}
OpenFSSpec(&myFSS);
}
err = AEDisposeDesc(docList);
return(err);
}
pascal OSErr AEHandleODOC(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
err = DoODOC(theAppleEvent, theReply);
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
return(err);
}
OSErr DoPDOC(theAppleEvent, theReply)
const AppleEvent *theAppleEvent, *theReply;
{
OSErr err;
FSSpec myFSS;
AEDescList *docList;
long items;
long index;
AEKeyword keywd;
DescType typeCode;
Size actualSize;
err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
if (err!=noErr) return (err);
err = AECountItems(docList, &items);
if (err!=noErr) return (err);
for (index=1; index<=items; index++)
{
err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode, (Ptr)&myFSS,
sizeof(myFSS), &actualSize );
if (err!=noErr)
{
AEDisposeDesc(docList);
return (err);
}
PrintFSSpec(&myFSS);
}
err = AEDisposeDesc(docList);
return(err);
}
pascal OSErr AEHandlePDOC(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
err = DoPDOC(theAppleEvent, theReply);
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
return(err);
}
int AppleEventInitialize(void)
{
#ifndef __MWERKS__
if (InstallFinder(kAEQuitApplication, AEHandleQUIT)) return kAppleEventError;
if (InstallFinder(kAEOpenApplication, AEHandleOAPP)) return kAppleEventError;
if (InstallFinder(kAEOpenDocuments, AEHandleODOC)) return kAppleEventError;
if (InstallFinder(kAEPrintDocuments, AEHandlePDOC)) return kAppleEventError;
#else
myQUITAEHandler = NewAEEventHandlerProc(AEHandleQUIT);
myOAPPAEHandler = NewAEEventHandlerProc(AEHandleOAPP);
myODOCAEHandler = NewAEEventHandlerProc(AEHandleODOC);
myPDOCAEHandler = NewAEEventHandlerProc(AEHandlePDOC);
if (InstallFinder(kAEQuitApplication, myQUITAEHandler)) return kAppleEventError;
if (InstallFinder(kAEOpenApplication, myOAPPAEHandler)) return kAppleEventError;
if (InstallFinder(kAEOpenDocuments, myODOCAEHandler)) return kAppleEventError;
if (InstallFinder(kAEPrintDocuments, myPDOCAEHandler)) return kAppleEventError;
#endif
return kNoError;
}